package com.example.student.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.student.R;
import com.example.student.bean.RecordBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.ViewHolder> {

    private Context mContext;
    private List<RecordBean> mList;

    public RecordAdapter(Context context, List<RecordBean> list) {
        this.mContext = context;
        this.mList = list;
    }

    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_record_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecordAdapter.ViewHolder holder, int position) {
        RecordBean recordBean = mList.get(position);
        String language = recordBean.getLanguage();
        if(!TextUtils.isEmpty(language)){
            holder.record_language.setText(language);
        }
        String time = recordBean.getTime();
        if(!TextUtils.isEmpty(time)){
            holder.record_time.setText(time);
        }

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView record_time, record_language;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);

            record_time = itemView.findViewById(R.id.record_time);
            record_language = itemView.findViewById(R.id.record_language);


        }
    }


}